Skip to content

TSRM: use local-exec TLS in PIE executables#22278

Closed
henderkes wants to merge 1 commit into
php:masterfrom
henderkes:perf/0-local-exec
Closed

TSRM: use local-exec TLS in PIE executables#22278
henderkes wants to merge 1 commit into
php:masterfrom
henderkes:perf/0-local-exec

Conversation

@henderkes

@henderkes henderkes commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

second split PR from #22231 (comment)

metricbefore (initial-exec)after (local-exec)Δ
PHPStan cycles221.87G219.49G−1.1%
PHPStan instructions281.99G282.06G+0.03%
PHPStan wall80.13s76.54s−4.5%

it's a small change, but it comes free. measurement on a local x86_64-linux-gnu machine, ignore the wall time

@arnaud-lb arnaud-lb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! Thank you!

I was wondering whether we could remove the tls_model attribute entirely, as when building a PIE the compiler should pick the local-exec model already. What actually happens is that it must emit initial-exec code when the TLS symbol is extern. That code is later relaxed by the linker, but still uses more instructions as relaxation must preserve the length of the code sequence.

So without the attribute the compiler emits a local-exec sequence like this:

movq    _tsrm_ls_cache@gottpoff(%rip), %rax
addq    %fs:0, %rax

Which gets relaxed to:

mov    $0xfffffffffffffffc,%rax
mov    %fs:(%rax),%eax

This avoids the GOT load and is more efficient than the initial-exec model, but this uses more instructions than the proper local-exec sequence which we get with __attribute__((tls_model("local-exec"))):

mov    %fs:0xfffffffffffffffc,%eax

@arnaud-lb arnaud-lb closed this in 21d4da2 Jun 25, 2026
@henderkes henderkes deleted the perf/0-local-exec branch June 25, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants